package com.wangsai.framework.supersecurity.example.cloud.server.controller;

import com.wangsai.framework.supersecurity.core.context.UserContext;
import com.wangsai.framework.supersecurity.example.cloud.commons.MyIUser;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

/**
 * @author Mr.Wang
 * @description
 * @date 2021-08-16 10:11
 */
@RestController
@RequestMapping
public class TestController {

    @GetMapping("/zuul")
    public String zuul() {
        Optional<MyIUser> userOptional = UserContext.currentUserOfNullable(MyIUser.class);
        return "this is zuul get by " + (userOptional.isPresent() ? userOptional.get().getUsername() : "unknown");
    }


    @GetMapping("/restTemplate")
    public String restTemplate() {
        Optional<MyIUser> userOptional = UserContext.currentUserOfNullable(MyIUser.class);
        return "this is restTemplate get by " + (userOptional.isPresent() ? userOptional.get().getUsername() : "unknown");
    }

}